#include <iostream>
using namespace std;
struct student{
    bool sex;
    string name;
    bool bIfPair;
};
int main()
{
     student students[50];
     int num;
     //输入学生信息
     cin>>num;
     for(int i = 0; i < num; i++)
     {
         cin >> students[i].sex >>  students[i].name;
         students[i].bIfPair = false;
     }
     //for(int i = 0; i < num; i++)
     //    cout << students[i].sex <<":"<<  students[i].name << endl;
    for(int i  = 0; i < num; i++)
    {
        if(!students[i].bIfPair)
        {
            cout<< students[i].name;
            for(int j = num-1; j>= 0; j--)
            {
                if((!students[j].bIfPair) && (students[i].sex != students[j].sex))
                {
                    students[i].bIfPair = true;
                    students[j].bIfPair = true;
                    cout<< " " << students[j].name << endl;
                    break;
                }
            }
        }
    }
}